package com.ecnu.web.controller.project;

import com.ecnu.common.core.controller.BaseController;
import com.ecnu.common.core.domain.AjaxResult;
import com.ecnu.common.core.domain.model.LoginUser;
import com.ecnu.common.core.page.PageDomain;
import com.ecnu.common.core.page.TableDataInfo;
import com.ecnu.system.mapper.ProjectStageMissionMapper;
import com.ecnu.system.service.IProjectPlanService;
import com.ecnu.system.service.IProjectService;
import com.ecnu.system.service.IProjectStageMissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;

@Api(tags = "统计管理")
@RestController
@RequestMapping("/statistic")
public class StatisticController extends BaseController {

    @Autowired
    private IProjectStageMissionService stageMissionService;

    /**
     * 项目成果统计
     * @param id 活动ID
     * @return
     */
    @GetMapping("/outcome")
    @ApiOperation(value = "成果统计")
    public AjaxResult statisticsOutcome(@NotBlank @RequestParam String id) {
        LoginUser loginUser = getLoginUser();
        return stageMissionService.statisticsOutcome(id,loginUser);
    }


    /**
     * 任务概览列表
     * missionId 任务ID
     * proId 项目ID
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "任务概览列表")
    public AjaxResult list(@NotBlank @RequestParam String missionId,
                           @NotBlank @RequestParam String proId) {
        LoginUser loginUser = getLoginUser();
        return stageMissionService.getStatisticList(missionId,proId,loginUser);
    }

    /**
     * 成果完成情况--未调整
     * @param missionId 任务ID
     * @param proId 活动ID
     * @param pageNum 当前页
     * @param pageSize 每页数量
     * @return
     */
    @GetMapping("/userDistribution")
    @ApiOperation(value = "成果完成情况")
    public TableDataInfo distribution(@NotBlank @RequestParam String missionId,
                                      @NotBlank @RequestParam String proId,
                                      @Min(1) @RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize) {
        LoginUser loginUser = getLoginUser();
        PageDomain domain = new PageDomain();
        domain.setPageNum(pageNum);
        domain.setPageSize(pageSize);
        return stageMissionService.getListForUser(missionId,proId, domain,loginUser);
    }

    /**
     * 相关成员列表
     */
    @GetMapping("/getTeamList")
    @ApiOperation(value = "相关成员列表")
    public AjaxResult getTeamList(String missionId, String proId,String userId) {
        LoginUser loginUser = getLoginUser();
        return stageMissionService.selectUserList(loginUser, missionId, proId,userId);
    }
    /**
     * 顶头：任务数，应交成果数，已交成果数，未交成果数
     */
    @GetMapping("/getInfo")
    @ApiOperation(value = "任务数，应交成果数，已交成果数，未交成果数")
    public AjaxResult Statistic(@NotBlank @RequestParam String id) {
        LoginUser loginUser = getLoginUser();
        return stageMissionService.infoList(id,loginUser);
    }
}
